import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
import Layout from '@/layout'
// console.log(window.sessionStorage.getItem('id'))
// const ids = window.sessionStorage.getItem('id')
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '工作台', icon: 'el-icon-s-operation' }
    }]
  },
  {
    path: '/manage-base-info',
    component: Layout,
    name: 'manage',
    meta: { title: '基础信息管理', icon: 'el-icon-date' },
    children: [
      {
        path: 'warehouse',
        name: 'warehouse',
        component: () => import('@/views/example/table/index'),
        meta: { title: '仓库管理' }
      },
      // detaill 区域
      {
        path: 'warehouse/detaill/:id',
        name: 'detaill',
        component: () => import('@/components/details/index.vue')
      },
      {
        path: 'area',
        name: 'area',
        component: () => import('@/views/example/tree/index'),
        meta: { title: '库区管理' }
      },
      // detaill 区域
      {
        path: 'area/detaill/:id',
        name: 'area/detaill',
        component: () => import('@/components/details/area.vue')
      },
      {
        path: 'location',
        name: 'location',
        component: () => import('@/views/example/location/index'),
        meta: { title: '库位管理' }
      },
      // detaill 区域
      {
        path: 'location/detaill/:id',
        name: 'location/detaill',
        component: () => import('@/views/example/location/component/index.vue')
      },
      {
        path: 'location-view',
        name: 'location-view',
        component: () => import('@/views/example/location-view/index'),
        meta: { title: '库位视图' }
      },
      {
        path: 'goods',
        name: 'goods',
        component: () => import('@/views/example/goods/index'),
        meta: { title: '货品管理' }
      },
      {
        path: 'goods-type',
        name: 'goods-type',
        component: () => import('@/views/example/goods-type/index'),
        meta: { title: '货品类型管理' }
      }
    ]
  },
  {
    path: '/manage-business',
    component: Layout,
    // redirect: '/home/left',
    name: 'Home',
    meta: { title: '商务管理', icon: 'el-icon-suitcase' },
    children: [
      { path: 'goods-owner',
        name: 'Left',
        component: () => import('@/views/home/left/index.vue'),
        meta: { title: '货主管理' }
      },
      {
        path: 'task-picking',
        name: 'Right',
        component: () => import('@/views/home/right/index.vue'),
        meta: { title: '承运商管理' }
      }
    ]
  },
  {
    path: '/manage-storage',
    component: Layout,
    name: 'manage-storage',
    meta: { title: '库内管理', icon: 'el-icon-s-release' },
    children: [
      {
        path: 'list',
        name: 'List',
        component: () => import('@/views/manage-storage/list/index.vue'),
        meta: { title: '盘点单' }
      },
      {
        path: 'list-task',
        name: 'List',
        component: () => import('@/views/manage-storage/list-task/index.vue'),
        meta: { title: '盘点任务' }
      },
      {
        path: 'storage-lose-profit',
        name: 'List',
        component: () => import('@/views/manage-storage/storage-lose-profit/index.vue'),
        meta: { title: '库存损益' }
      },
      {
        path: 'latest-storage',
        name: 'List',
        component: () => import('@/views/manage-storage/latest-storage/index.vue'),
        meta: { title: '实时库存' }
      }
    ]
  },
  {
    path: '/manage-storage-in/list-in',
    component: Layout,
    name: 'manage-storage-in',
    // redirect: '/manage-storage-in/list-in',
    meta: { title: '入库管理', icon: 'el-icon-sell' },
    children: [
      {
        path: 'list',
        name: 'List',
        component: () => import('@/views/manage-storage-in/list-in/list/index.vue'),
        meta: { title: '入库单' }
      },
      {
        path: 'task-receive',
        name: 'task-receive',
        component: () => import('@/views/manage-storage-in/list-in/task-receive/index.vue'),
        meta: { title: '收货任务' }
      },
      {
        path: 'task-add',
        name: 'task-add',
        component: () => import('@/views/manage-storage-in/list-in/task-add/index.vue'),
        meta: { title: '上架任务' }
      }
    ]
  },
  {
    path: '/manage-storage-out',
    component: Layout,
    name: 'manage-storage-out',
    meta: { title: '出库管理', icon: 'el-icon-sold-out' },
    children: [
      {
        path: 'list-out',
        name: 'list-out',
        component: () => import('@/views/manage-storage-out/list-out/index.vue'),
        meta: { title: '出库单' }
      },
      {
        path: 'task-picking',
        name: 'task-picking',
        component: () => import('@/views/manage-storage-out/task-picking/index.vue'),
        meta: { title: '练货任务' }
      },
      {
        path: 'manage-task-transfer',
        name: 'manage-task-transfer',
        component: () => import('@/views/manage-storage-out/manage-task-transfer/index.vue'),
        meta: { title: '交接任务' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
